package groovy.com.wz.test

import spock.lang.Specification

class UnitTest extends Specification {

    AccountService accountService = Mock()
    UserService userService = Stub()

    def '账号是否添加成功'() {
        given:

//            userService.getUserByUserId("100") >> new User("100","wang", 1, "1111")
            User user = new User("100","wang", 1, "1111")
            userService.getUserByUserId(_ as String) >> user
            userService.isLogin(_ as User) >> true

//            accountService.getAccount(_ as String) >> null
            TestService testService = new TestService(accountService, userService)
        when:
            testService.getAccount("100")
        then:
//            1 * userService.getUserByUserId(_ as String)
//            userService.isLogin(_ as User) == true
//             1 * accountService.getAccountByAccountId(_ as String)
        1 * accountService.getAccountByAccountId(_)
    }

    def '账号是否添加正确'() {
        given:
              UserService uService = new UserService()
              AccountService accService = new AccountService();
              TestService testService = new TestService(accService, uService)
        expect:
              testService.getAccount(a) == b
        where:
              a || b
          "100" ||  new Account("100","100")
          "200" ||  new Account("200","200")
    }
}